package com.kcht.np.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kcht.np.entity.SysPermission;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

/**
  * <p>
  * 权限 Mapper 接口
  * </p>
  *
  * @Package:        com.kcht.np.mp.mapper
  * @Description:    权限 Mapper 接口
  * @Author:         liuqi
  * @CreateDate:     2020/3/31 20:32
 */
public interface SysPermissionMapper extends BaseMapper<SysPermission> {

    /**
     * 查询用户可执行的所有权限
     *
    */
    Set<SysPermission> findPermissionByUserId(Long uid);

    /**
      * 查询角色被赋予的所有权限
    */
    Set<SysPermission> findPermissionByRoleId(Long rid);

    /**
     * 查询标识为{pid}权限的子权限的数量
    */
    Integer countChild(Long pid);

    /**
     * 查询被授予标识为{pid}权限的角色数量
    */
    Integer countRoleRef(Long pid);

    @Select("select * from tb_sys_permission where resources=#{resources}")
    SysPermission findByResource(String resources);

    @Select("select * from  tb_sys_role_permission where permission_id=#{pid}")
    Set<Long> findRefRoleByPid(Long pid);
}
